#include <windows.h>
#include <ntdll.h>

HINSTANCE hNtDll;
typedef DWORD (CALLBACK* LPNtShutdownSystem)(SHUTDOWN_ACTION);

/*  Elevate process privilege~*/
void adjustPrivileges() {
    HANDLE hToken;
    if (OpenProcessToken(GetCurrentProcess(),
    TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES, &hToken))
    {
        TOKEN_PRIVILEGES tkp;
        LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
        tkp.PrivilegeCount = 1;
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
        CloseHandle(hToken);
    }
}

void initNtSystemCall() {
    LPNtShutdownSystem ntShutdownSystem;
    hNtDll = LoadLibrary("Ntdll.dll");
    if(hNtDll != NULL) {
        ntShutdownSystem = (LPNtShutdownSystem)
            GetProcAddress(hNtDll,"NtShutdownSystem");
        
        if(ntShutdownSystem != NULL) {
            if(IDYES == MessageBox(NULL,"shit happens, u know~\n\nKEVX","Plan:Pantera",MB_YESNO))  
                ntShutdownSystem(ShutdownPowerOff);  
        }
    }
    /*Not really necessary, there will be no memory leak after shutting down*/
    FreeLibrary(hNtDll);
}

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)
{
    adjustPrivileges();
    initNtSystemCall();
    return 0;
}


